deferred class IUP_WIDGET_SHOW
-- Commands to show dialogs.

inherit
	IUP_WIDGET_INTERNALS
	
insert
	IUP_INTERFACE

feature {ANY}

	show : STRING
		-- Show the dialog at screen, return IUP_NOERROR if successful.
		-- If there was an error returns IUP_ERROR.
		local
			r: INTEGER
		do
			r := int_show(widget)

			if r.is_equal(0) then
				Result := "IUP_NOERROR"
			else
				Result := "IUP_ERROR"
			end
		end

	show_predefined_xy (x, y: STRING): STRING
		-- Displays a dialog in a given position on the screen using predefined
		-- values. However you can combine a predefined value with an integer (as 
		-- string). If there was an error returns IUP_ERROR.
		--
		-- x: The following predefined values can be used:
		--
		--  IUP_LEFT: Positions the dialog on the left corner of the main screen
		--  IUP_CENTER: Horizontally centralizes the dialog on the main screen
		--  IUP_RIGHT: Positions the dialog on the right corner of the main screen
		--  IUP_MOUSEPOS: Positions the dialog on the mouse position
		--  IUP_CENTERPARENT: Horizontally centralizes the dialog relative to its 
		--                    parent
		--  IUP_CURRENT: use the current position of the dialog.
		--
		-- y: The following predefined calues can be used:
		--
		-- IUP_TOP: Positions the dialog on the top of the main screen
		-- IUP_CENTER: Vertically centralizes the dialog on the main screen
		-- IUP_BOTTOM: Positions the dialog on the base of the main screen
		-- IUP_MOUSEPOS: Positions the dialog on the mouse position
		-- IUP_CENTERPARENT: Vertically centralizes the dialog relative to its 
		--                   parent
		-- IUP_CURRENT: use the current position of the dialog.
		require
			is_valid_position(x, y)
		do
			Result := show_xy(iup_open.position_to_integer(x),
									iup_open.position_to_integer(y))
		end

	show_xy (x, y: INTEGER): STRING
		-- Displays a dialog in a given position on the screen. If there was an 
		-- error returns IUP_ERROR.
		--
		-- x: horizontal position of the top left corner of the window, relative 
		--    to the origin of the main screen.
		--
		-- y: vertical position of the top left corner of the window, relative to 
		--    the origin of the main screen.
		require
			x >= 0
			y >= 0
		local
			r: INTEGER
		do
			r := int_show_xy(widget, x, y)
			
			if r.is_equal(-1) then
				Result := "IUP_INVALID"
			elseif r.is_equal(0) then
				Result := "IUP_NOERROR"
			else
				Result := "IUP_ERROR"
			end
		end

feature {}

	-- Internals

	int_show (dlg: POINTER): INTEGER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupShow"
         }"
      end

	int_show_xy (wdt: POINTER; x, y: INTEGER): INTEGER
		external "plug_in"
      alias "{
         location: "${sys}/plugins"
         module_name: "iup"
         feature_name: "IupShowXY"
         }"
      end

	-- Validations

	is_valid_position (x, y: STRING): BOOLEAN
		local
			xs, ys: BOOLEAN
		do
			if x.is_equal("IUP_LEFT") or
				x.is_equal("IUP_CENTER") or
				x.is_equal("IUP_RIGHT") or
				x.is_equal("IUP_MOUSEPOS") or
				x.is_equal("IUP_CENTERPARENT") or
				x.is_equal("IUP_CURRENT") then
				xs := True
			elseif x.is_integer and x.to_integer >= 0 then
				xs := True
			else
				xs := False
			end

			if y.is_equal("IUP_TOP") or
				y.is_equal("IUP_CENTER") or
				y.is_equal("IUP_BOTTOM") or
				y.is_equal("IUP_MOUSEPOS") or
				y.is_equal("IUP_CENTERPARENT") or
				y.is_equal("IUP_CURRENT") then
				ys := True
			elseif y.is_integer and y.to_integer >= 0 then
				ys := True
			else
				ys := False
			end

			if xs and ys then
				Result := True
			else
				Result := False
			end
		end

end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2017 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
